package allod.som.functions.topological

import Math._
import allod.som.Lattice.NeuronLocation

/**
 * Created by IntelliJ IDEA.
 * User: allod
 * Date: 6 січ 2010
 * Time: 22:17:49
 */

case class Gaussian(val sigma0: Double, val tau1: Double) extends TopologicalFunction {
  def topologicalDistance(winnerIndex: NeuronLocation, looserIndex: NeuronLocation) = {
    sqrt(pow(winnerIndex._1 - looserIndex._1, 2) + pow(winnerIndex._2 - looserIndex._2, 2))
  }

  def topologicalNeighbourhood(winnerIndex: NeuronLocation, looserIndex: NeuronLocation, iteration: Int) = {
    exp(-pow(topologicalDistance(winnerIndex, looserIndex), 2) / (2 * pow(effectiveWidth(iteration), 2)))
  }

  def effectiveWidth(iteration: Int) =
    if (iteration < 1000)
      sigma0 * exp(-iteration / tau1)
    else
      sigma0 * exp(-(1000 + sqrt(iteration)) / tau1)
}